package cave.ui;

import cave.renderer.Texture;
import cave.renderer.TextureManager;
import cave.utils.CharMap;

public class Font {
	
	private CharMap<Texture> textures;
	private float charAspectRatio;
	
	public Font(float charWidth, float charHeight, float charAspectRatio, int charsOnRow, TextureManager.Atlas atlas, String characters) {
		
		textures = new CharMap<Texture>();
		this.charAspectRatio = charAspectRatio;
		
		int row = 0, column = 0;
		int numChars = characters.length();
		for (int i = 0; i < numChars; ++i) {
			
			textures.put(characters.charAt(i), new Texture(column*charWidth, 1.0f - (row+1)*charHeight, charWidth, charHeight, atlas));

			if (++column >= charsOnRow) {
				column = 0;
				row++;
			}
		}
		
		atlas.incUsers();
	}
	
	public Texture getTexture(char character) {
		return textures.get(character);
	}
	
	public float getCharAspectRatio() {
		return charAspectRatio;
	}
}
